package sse.ustc.cc.activity;

import sse.ustc.cc.util.ClearEditText;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

public class LoginAty extends Activity {
	private Toast mToast;
	private TextView regText;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		requestWindowFeature(Window.FEATURE_NO_TITLE);//去掉标题栏
		super.onCreate(savedInstanceState);
		setContentView(R.layout.login);

		final ClearEditText username = (ClearEditText) findViewById(R.id.username);
		final ClearEditText password = (ClearEditText) findViewById(R.id.password);
		regText = (TextView) findViewById(R.id.regist);
		
		((Button) findViewById(R.id.login)).setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				if(TextUtils.isEmpty(username.getText())){
					//设置晃动
					username.setShakeAnimation();

					showToast("用户名不能为空");
					return;
				}
				
				if(TextUtils.isEmpty(password.getText())){
					password.setShakeAnimation();
					showToast("密码不能为空");
					return;
				}
			}
		});
		
		regText.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				 Intent intent = new Intent(LoginAty.this, RegisterAty.class);
				 startActivity(intent);
			}
		});
	}
	
	/**
	 * 显示Toast消息
	 * @param msg
	 */
	private void showToast(String msg){
		if(mToast == null){
			mToast = Toast.makeText(this, msg, Toast.LENGTH_SHORT);
		}else{
			mToast.setText(msg);
		}
		mToast.show();
	}


}
